#include "pch.h"
#include "ImageDisplayItem.h"
#include "DisplayContext.h"
#include "DXTools.h"
#include <ppltasks.h>

using namespace D2D1;
using namespace Microsoft::WRL;
using namespace concurrency;
ImageDisplayItem::ImageDisplayItem(void)
{
	m_isImageLoaded=false;
}


ImageDisplayItem::~ImageDisplayItem(void)
{

}

void ImageDisplayItem::Create(DisplayContext &dislpayEngine)
{
	DisplayItem::Create(dislpayEngine);
}

void ImageDisplayItem::SetSource(Windows::Storage::StorageFile^ file)
{
	m_isImageLoaded=false;
	targetImageFile=file;
	DXTools::CreateBitmapFromFile(targetImageFile,m_displayContext->WICFactory,m_displayContext->D2DContext,renderImage.GetAddressOf());
	m_isImageLoaded=true;
}

void ImageDisplayItem::Render(DisplayContext &dislpayEngine)
{
	if(targetImageFile==nullptr)
		return;
	if(!m_isImageLoaded)
		return;
	if(renderImage.Get()==NULL)
		return;
	Matrix3x2F transform = Matrix3x2F::Translation(RenderTransform.TranslateX,RenderTransform.TranslateY);
	dislpayEngine.D2DContext->SetTransform(transform);

	D2D1_SIZE_U imageSize;
	imageSize.width=Width;
	imageSize.height=Height;
	dislpayEngine.D2DContext->DrawBitmap(renderImage.Get(),RectF(X,Y,Width+X,Height+Y));
}
